// #ifdef MP-WEIXIN
const  logManager =  wx.getLogManager({level: 1})
const logger = wx.getRealtimeLogManager();
// #endif
let systemInfo = null;
let openId = uni.getStorageSync('openId') || ''
let userId = (uni.getStorageSync('userInfo')&&uni.getStorageSync('userInfo').userId) || '';
const { version } = require('@/utils/api/baseUrl.js')
uni.getSystemInfo({
	success: (res)=> {
		systemInfo = res.deviceModel+res.system;
	}
});
function getCurrentTime(){
	let time = new Date()
	let hour = buZero(time.getHours())
	let min = buZero(time.getMinutes())
	let second = buZero(time.getSeconds())
	let millSecond = buZero(time.getMilliseconds())
	let time1 = hour +':'+ min +':'+ second +':'+millSecond
	return time1
}
function buZero(number) {
  return number < 10 ? '0' + number : number;
}
export function logs(data,type,isShow = true){
	let appletVersion = version;
	let envVersion = '';
	// #ifdef MP-WEIXIN
	envVersion = __wxConfig.envVersion
	// #endif
	let json = {...data,time:getCurrentTime(),version:envVersion,systemInfo:systemInfo,userId:userId,openId:openId,appletVersion:appletVersion}
	// #ifdef MP-WEIXIN
	logManager.log(json)
	if(isShow){
		if(type == 'error'){
			logger.error(json)
		}else{
			logger.info(json)
		}
	}
	// #endif
}
